//
//  RWLXViewController.m
//  VmiSJ
//
//  Created by Apple on 2017/1/10.
//  Copyright © 2017年 汪的一声就哭了！. All rights reserved.
//

#import "RWLXViewController.h"

@interface RWLXViewController ()<UITableViewDelegate, UITableViewDataSource>
@property(nonatomic,strong) UITableView *tableView;

@end

@implementation RWLXViewController
{
    NSMutableArray *_listArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"结束时间";
    [self obtainListData];
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.backgroundColor = BackColor;
    _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    
    [self.view addSubview:_tableView];
    
    [_tableView registerNib:[UINib nibWithNibName:@"JSSJTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell1"];
    
    
}
//设置单元格高度
- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}
//设置表视图中的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _listArray.count;
}

//设置单元格中的数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    JSSJTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
    [cell.mainImageView sd_setImageWithURL:[NSURL URLWithString:[_listArray[indexPath.row] img_url]] placeholderImage:[UIImage imageNamed:@"占位图"]];
    cell.label.text = [_listArray[indexPath.row] c_name];
    if ([_typeStr isEqualToString:[_listArray[indexPath.row] c_name]]) {
        cell.backImageView.hidden = NO;
    } else {
        cell.backImageView.hidden = YES;
    }
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    for (NSInteger i = 0; i < _listArray.count; i++) {
        JSSJTableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
        cell.backImageView.hidden = YES;
    }
    JSSJTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.backImageView.hidden = NO;
    [self.delegate RWLXViewControllerSendType:_listArray[indexPath.row]];
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -------------- 任务类型网络请求
- (void)obtainListData
{
    [NetRequiest handleDataWithString:[NSString stringWithFormat:@"%@",HTTPLOAD] dictionary:@{@"v1":@"taskclassify"} HUD:YES block:^(id responseObject) {
        if ([responseObject[@"code"] isEqual:@200]) {
            _listArray = [NSMutableArray array];
            for (NSDictionary *dic in responseObject[@"result"]) {
                RWLXModel *model = [[RWLXModel alloc] init];
                [model setValuesForKeysWithDictionary:dic];
                [_listArray addObject:model];
            }
            [self.tableView reloadData];
        } else {
            [[SQShowMessage shareMessage] showMessageWithStr:responseObject[@"msg"]];
        }
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
